# -*- coding: utf-8 -*-
'''
@author: wangwl
@file: docker
@time: 2021/09/14 10:57
@desc:
'''
import os, django

from general.deploy.jar import DeployJar


class DeployUrl():
    def __init__(self, soft_install_code, soft_info_one, soft_conf_info):
        self.soft_install_code = soft_install_code
        self.soft_info_one = soft_info_one
        self.soft_conf_info = soft_conf_info

    def exec_deploy(self):
        from components.deploy.soft_release.dao import deploy_event_in

        if self.soft_install_code == "docker":
            from general.deploy.docker import DeployDocker
            deploy_docker = DeployDocker(self.soft_info_one, self.soft_conf_info)
            try:
                deploy_docker.set_ssh()
            except Exception as e:
                deploy_event_in(self.soft_info_one['deploy_event_ids'],
                                '连接服务器失败(%s)' % e, "0")
                return
            try:
                deploy_docker.exec_install_docker()
            except Exception as e:
                print(e)
                return
            deploy_docker.ssh_close()

        elif self.soft_install_code == "zip":
            pass

        elif self.soft_install_code == "jar":
            deploy_jar = DeployJar(self.soft_info_one, self.soft_conf_info)
            try:
                deploy_jar.set_ssh()
            except Exception as e:
                deploy_event_in(self.soft_info_one['deploy_event_ids'],
                                '连接服务器失败(%s)' % e, "0")
            try:
                deploy_jar.exec_install_()
            except Exception as e:
                print(e)
                return
            deploy_jar.ssh_close()

        return True